const fs = require("fs");
const cwd = process.cwd();
const path = require("path");
const buildConf = require("./conf.js");
function join(paths){return path.join(__dirname, paths)};

const excludeList = [`wxm-pc`, `wxm-app`, `ctools`];

module.exports = function getTemplateConfs(packageJsons, conf) {
  const {smallHump} = conf;
  const names = packageJsons.map(item => item.name).filter(item => !excludeList.includes(item));
  const baseContent = fs.readFileSync(join(`./indexHtml.temp.js`));
  const midContent = names.map(item =>
    `import ${smallHump(item)} from "${item}";`
  ).join("\n  ");
  const tailContent = `init([${names.map(item => smallHump(item)).join(",") }]);`;

  conf.dir.mk(path.join(conf.workspacePath, `./src`))
  fs.writeFileSync(path.join(conf.workspacePath, `./src/main.js`), `${baseContent}${midContent}\n\n${tailContent}`);
};
